<%--
  Created by IntelliJ IDEA.
  User: 29688
  Date: 2021/4/1
  Time: 12:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>设置我的密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui-v2.5.7/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui-v2.5.7/style/admin.css" media="all">
    <script src="${pageContext.request.contextPath}/layui-v2.5.7/layui/layui.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.js" type="text/javascript"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">修改密码</div>
                <div class="layui-card-body" pad15>

                    <form class="layui-form" >
                        <input type="hidden" name="uname" id="uname" value="${user.uname}"   class="layui-input">
                        <div class="layui-form-item">
                            <label class="layui-form-label">输入旧密码</label>
                            <div class="layui-input-inline">
                                <input type="password" id="oldPassword" name="oldPassword" required  lay-verify="required" placeholder="请输入旧密码" autocomplete="off" class="layui-input" >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">输入新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="password" required lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">
                            </div>

                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">确认新密码</label>
                            <div class="layui-input-inline">
                                <input type="password" name="rePassword" required lay-verify="required" placeholder="请确认密码" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="button" class="layui-btn" lay-submit lay-filter="formDemo" value="提交">
                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>


<script>
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer = layui.layer;
        $("#oldPassword").blur(function(){
            $.ajax({
                url:"/user/checkPassword",
                data:{"oldPassword":$("#oldPassword").val(),"uname":$("#uname").val()},
                success:function (data){
                    if(data===1){
                        layer.msg("密码不正确！");
                    }
                }
            })
        })

        //监听提交
        form.on('submit(formDemo)', function(data){
            var field = data.field
            if(data.field.password!==data.field.rePassword)
            {
                layer.msg("两次输入密码不一致!");
                console.log(data.field.password+"!="+data.field.rePassword)
                return false;
            }
            else {
                $.ajax({
                    url:'changePassword',
                    type:"post",
                    data:field,
                    success:function (data){
                        if(data===1){
                            layer.msg("修改成功")
                        }else {
                            layer.msg("密码错误！")
                        }
                    }
                })
            }
        });
    });

</script>
</body>
</html>
